home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / unx2dos.c < prev    next >
C/C++ Source or Header  |  1994-01-15  |  3KB  |  209 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <osbind.h>
  5. #include <types.h>
  6. #include <param.h>
  7. #include <support.h>
  8. #include "lib.h"
  9.  
  10. extern int __mint;
  11. extern char _rootdir;    /* in main.c: user's preferred root directory */
  12.  
  13. int _unixmode;        /* not used right now */
  14.  
  15. /*
  16.  * returns 0 for ordinary files, 1 for special files (like /dev/tty)
  17.  */
  18.  
  19. int
  20. _unx2dos(unx, dos)
  21.     const char *unx;
  22.     char *dos;
  23. {
  24.     const char *u;
  25.     char *d, c;
  26.  
  27.     dos[0] = 0;
  28.     u = unx; d = dos;
  29.     if (!strncmp(u, "/dev/", 5)) {
  30.         u += 5;
  31.     /* make /dev/A/foo the same as A:/foo */
  32.  
  33.         if (*u && isalpha (*u)
  34.             && (u[1] == 0 || (u[1] == '/' || u[1] == '\\'))) {
  35.             d[0] = *u++;
  36.             d[1] = ':';
  37.             d += 2;
  38.         }
  39.     /* check for a unix device name */
  40.         else if (__mint) {
  41.             if (__mint >= 8) {
  42.                 strcpy(d, "U:\\dev\\"); d += 7;
  43.             } else {
  44.                 strcpy(d, "V:\\");
  45.                 d += 3;
  46.             }
  47.         }
  48.         else {
  49.             strcpy(d, u);
  50.             strcat(d, ":");
  51.             if (!strcmp(d, "tty:"))
  52.                 strcpy(d, "con:");
  53.             return 1;
  54.         }
  55.     } else if (__mint && !strncmp(u, "/pipe/", 6)) {
  56.         u += 6;
  57.         if (__mint >= 9) {
  58.             strcpy(d, "U:\\pipe\\"); d += 8;
  59.         } else {
  60.             strcpy(d, "Q:\\"); d += 3;
  61.         }
  62.     } else if (*u == '/' && _rootdir) {
  63.         *d++ = _rootdir;
  64.         *d++ = ':';
  65.     }
  66.  
  67.     while( (c = *u++) != 0 ) {
  68.         if (c == '/')
  69.             c = '\\';
  70. #if 0
  71. /* translate "c:/foo/d:/bar" into "d:\bar" */
  72.         else if (c == ':') {
  73.             if (   (d > &dos[1] && d[-2] == '\\')
  74.                 || (d == &dos[1]) ) {
  75.                 *dos = d[-1];
  76.                 d = dos+1;
  77.             }
  78.         }
  79. #endif
  80.         *d++ = c;
  81.     }
  82.     *d = 0;
  83.     return 0;
  84. }
  85.  
  86. int
  87. _dos2unx(dos, unx)
  88.     const char *dos;
  89.     char *unx;
  90. {
  91.     register char c;
  92.  
  93.     /* replace A:\x with /dev/a/x,
  94.      * replace A:\x with /x, if _rootdir is 'a',
  95.      * replace A:\x with /a/x, if _rootdir is 'u'.
  96.      * BUG/FEATURE: A:x is converted to A:\x, you lose the feature
  97.      *              of one current directory per device.
  98.      *              This is because we assume that /dev/a/x is always 
  99.      *              an absolute path.
  100.      */ 
  101.     if (*dos && dos[1] == ':') {
  102.         register char dev = tolower(*dos);
  103.         dos += 2;
  104.         if (dev != _rootdir) {
  105.             if (_rootdir != 'u') {
  106.                 *unx++ = '/'; *unx++ = 'd'; 
  107.                 *unx++ = 'e'; *unx++ = 'v';
  108.             }
  109.             *unx++ = '/';
  110.             *unx++ = dev;
  111.         }
  112.         if (*dos != '/' && *dos != '\\') {
  113.                 *unx++ = '/';
  114.         }
  115.     }
  116.     /* convert slashes
  117.      */
  118.     while ( (c = *dos++) != 0) {
  119.         if (c == '\\')
  120.             c = '/';
  121.         else if (__mint < 7)
  122.             c = tolower(c);
  123.         *unx++ = c;
  124.     }
  125.     *unx = 0;
  126.     return 0;
  127. }
  128.  
  129. #ifdef __GNUC__
  130.  
  131. asm(".stabs \"_unx2dos\",5,0,0,__unx2dos"); /* dept of clean tricks */
  132. asm(".stabs \"_dos2unx\",5,0,0,__dos2unx"); /* dept of clean tricks */
  133.  
  134. #else /* ! __GNUC__ */
  135.  
  136. int
  137. unx2dos(unx, dos)
  138.         const char *unx;
  139.         char *dos;
  140. {
  141.     return _unx2dos(unx, dos);
  142. }
  143.  
  144. int
  145. dos2unx(dos, unx)
  146.         const char *dos;
  147.         char *unx;
  148. {
  149.     return _dos2unx(dos, unx);
  150. }
  151.  
  152. #endif
  153.  
  154. int
  155. _path_unx2dos(unx, dos)
  156.     const char *unx;
  157.     char *dos;
  158. {
  159.     char buf[MAXPATHLEN], *s;
  160.         
  161.     while (*unx) {
  162.         s = buf;
  163.         while (*unx) {
  164.             if (*unx == ':') {
  165.                 unx++;
  166.                 break;
  167.             }
  168.             *s++ = *unx++;
  169.         }
  170.         *s = 0;
  171.         _unx2dos(buf, dos);
  172.         while (*dos)
  173.             dos++;
  174.         if (*unx)
  175.           *dos++ = ',';
  176.     }        
  177.  
  178.     *dos = 0;
  179.     return 0;
  180. }        
  181.  
  182. int 
  183. _path_dos2unx(dos, unx)
  184.     const char *dos;
  185.     char *unx;
  186. {
  187.     char buf[MAXPATHLEN], *s;
  188.  
  189.     while (*dos) {
  190.         s = buf;
  191.         while (*dos) {
  192.             if (*dos == ';' || *dos == ',') {
  193.                 dos++;
  194.                 break;
  195.             }
  196.             *s++ = *dos++;
  197.         }
  198.         *s = 0;
  199.         _dos2unx(buf, unx);
  200.         while (*unx)
  201.             unx++;
  202.         if (*dos)
  203.           *unx++ = ':';
  204.     }
  205.  
  206.     *unx = 0;
  207.     return 0;
  208. }
  209.